package cn.mw.cmdb.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

public class InventoryCheck {
    @Getter
    public enum InventoryResultEnum {
        SHORTAGE("SHORTAGE","盘亏"), // 盘亏
        MATCH("MATCH","相符"),    // 相符
        SURPLUS("SURPLUS","盘盈");  // 盘盈

        private final String code;

        private final String desc;

        InventoryResultEnum(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }
        public static InventoryResultEnum getEnum(String code){
            return Arrays.stream(InventoryResultEnum.values()).filter(t->t.getCode().equals(code)).findFirst().orElseGet(null);
        }
    }

    public static class InventoryItem {
        private int count;          // 原始数量
        private int inventoryCount; // 盘点数量

        // 构造函数、getter 和 setter 省略
        public InventoryItem(int count, int inventoryCount) {
            this.count = count;
            this.inventoryCount = inventoryCount;
        }

        public int getCount() {
            return count;
        }

        public int getInventoryCount() {
            return inventoryCount;
        }
    }

    public static InventoryResultEnum checkInventoryStatus(List<InventoryItem> items) {
        boolean hasShortage = false;
        boolean hasSurplus = false;

        for (InventoryItem item : items) {
            if (item.getInventoryCount() < item.getCount()) {
                hasShortage = true;
            } else if (item.getInventoryCount() > item.getCount()) {
                hasSurplus = true;
            }
        }

        if (hasShortage) {
            return InventoryResultEnum.SHORTAGE; // 盘亏
        } else if (hasSurplus) {
            return InventoryResultEnum.SURPLUS; // 盘盈
        } else {
            return InventoryResultEnum.MATCH; // 相符
        }
    }

    public static void main(String[] args) {
        // 示例数据
        List<InventoryItem> items = List.of(
            new InventoryItem(1, 4), // 相符
            new InventoryItem(2, 4), // 相符
            new InventoryItem(3, 4)  // 相符
        );

        InventoryResultEnum status = checkInventoryStatus(items);
        System.out.println("Inventory Status: " + status);
    }
}